//
// Created by Administrator on 2021/8/2.
//
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string>

using namespace std;

class Solution {
public:
    bool isAnagram(string s, string t) {
        if (s.size() != t.size()) return false;
        // 用数组代替hash
        vector<int> counter(26, 0);
        for (auto &x:s) {
            ++counter[x - 'a'];
        }
        for (auto &x:t) {
            --counter[x - 'a'];
        }
        for (int i = 0; i < 26; ++i) {
            if (counter[i] != 0)
                return false;
        }
        return true;

    }
};

int main() {
    Solution solution;
    cout << solution.isAnagram("anagram", "nagaram") << endl;
    cout << solution.isAnagram("rat", "car") << endl;
    return 0;
}
